package biz;

import java.util.HashMap;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import dao.IDepartmentDao;
import entity.Department;
import util.Config;

@Service
public class DepartmentBiz implements IDepartmentBiz {
	@Resource
	private IDepartmentDao deptdao;
	public boolean addDepartment(Department dept) {
		deptdao.addDepartment(dept);
		return true;
	}

	public boolean delectDepartment(int id) {
		deptdao.delectDepartment(id);
		return true;
	}

	public boolean updateDepartment(int id, String name, String info) {
		return true;
	}

	public List<Department> selectAllDepartment() {
		List<Department> list = deptdao.selectAllDepartment();
		return list;
	}

	public List<Department> selectDepartment(String name, String info, int curpage) {
		HashMap map = new HashMap();
		if(name!=null&&!name.trim().equals(""))
			map.put("name", "%"+name+"%");
		if(info!=null&&!info.trim().equals(""))
			map.put("info", "%"+info+"%");
		
		int begin = Config.pagesize * (curpage - 1);
		map.put("begin", begin);
		
		map.put("pagesize",Config.pagesize);
		
		List<Department> list = deptdao.selectDepartment(map);
		return list;
	}

	public int getPageSize(String name, String info) {
		HashMap map = new HashMap();
		if(name!=null&&!name.trim().equals(""))
			map.put("name", "%"+name+"%");
		if(info!=null&&!info.trim().equals(""))
			map.put("info", "%"+info+"%");
		int count = deptdao.getDepartmentCount(map);//拿到条件查询的总记录数
		
		int result = 0;
		if(count%Config.pagesize==0)
			result = count/Config.pagesize;
		else
			result = count/Config.pagesize+1;
		return result;
	}

	

}
